package org.jsola.contract.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 档案类型
 *
 * @author JanusMix
 */
public enum FileType implements IConst {

    /**
     * 固定期限劳动合同
     */
    LABORCONTRACTLIMIT("laborContractLimit","固定期限劳动合同"),
    /**
     * 无固定期限劳动合同
     */
    LABORCONTRACTUNLIMIT("laborContractUnlimit","无固定期限劳动合同"),
    /**
     * 以完成一定工作任务为期限的劳动合同
     */
    LABORCONTRACTJOBS("laborContractJobs","以完成一定工作任务为期限的劳动合同"),
    /**
     * 实习协议
     */
    INTERNACCORDS("internAccords","实习协议"),
    /**
     * 劳务合同
     */
    LABORCONTRACT("laborContract","劳务合同"),
    /**
     * 返聘协议
     */
    REEMPLOYACCORDS("reemployAccords","返聘协议"),
    /**
     * 劳务派遣合同
     */
    LABORCONTRACTDISPATCH("laborContractDispatch","劳务派遣合同"),
    /**
     * 借调合同
     */
    BORROWEDCONTRACT("borrowedContract","借调合同"),
    /**
     * 约定书
     */
    ENGAGEMENTLETTER("engagementLetter","约定书"),
    /**
     * 兼职合同
     */
    PARTTIME("partTime","兼职合同"),
    /**
     * 其它
     */
    OTHER("other","其它"),
    /**
     * 离职合同
     */
    DIMISSION_CONTRACT("dimissionContract","离职合同"),
    /**
     * 退休返聘合同
     */
    RETIRE_RE_EMPLOY("retireReEmploy","退休返聘合同"),
    /**
     * 见习协议
     */
    NOVICIATE_AGREEMENT("noviciateAgreement","见习协议");

    private final String value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "laborContractLimit,laborContractUnlimit,laborContractJobs,internAccords,laborContract,reemployAccords,laborContractDispatch,borrowedContract,engagementLetter,partTime,other,dimissionContract,retireReEmploy,noviciateAgreement";

     /**
     * 缓存所有value
     */
    private static final Map<String, FileType> LOOKUP = new HashMap<>();

    static {
        for (FileType e : FileType.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    FileType(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找FileType
     * @param value value
     * @return FileType
     */
    public static FileType find(String value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找FileType
     * @param desc desc
     * @return FileType
     */
    public static FileType findByDesc(String desc){
        for (FileType e : FileType.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (FileType e : FileType.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        String value = (String) obj;
        return find(value) != null;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
